//
//  LSZSearchResultsTableViewCell.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/12/15.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZSearchResultsTableViewCell.h"

@implementation LSZSearchResultsTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.labelContent = [[UILabel alloc]init];
        self.labelContent.textColor =  titleColorLSZ;
        self.labelContent.numberOfLines = 3;
        [LSZSpecialPackaging setLabelAdaptiveSize:self.labelContent font:14.5];
        [self addSubview:self.labelContent];

        self.labelRemark = [[UILabel alloc]init];
        self.labelRemark.textColor = lightColor;
        [LSZSpecialPackaging setLabelAdaptiveSize:self.labelRemark font:11];

        [self addSubview:self.labelRemark];

        self.imageViewRight  = [[UIImageView alloc]init];
        [self addSubview:self.imageViewRight];

        self.butSmall = [[UIButton alloc]init];
        self.butSmall.backgroundColor = RGBColor(0, 0, 0);
        self.butSmall.alpha = 0.6;
        [self.butSmall.layer setMasksToBounds:YES];
        self.butSmall.hidden = YES;
        [self.imageViewRight addSubview:self.butSmall];

        UIImageView * imageViewSanJiao = [[UIImageView alloc]init];
        imageViewSanJiao.image = [UIImage imageNamed:@"白三角"];
        [self.butSmall addSubview:imageViewSanJiao];

        self.labelTime = [[UILabel alloc]init];
        self.labelTime.textAlignment = NSTextAlignmentLeft;
        self.labelTime.textColor = [UIColor whiteColor];
        [LSZSpecialPackaging setLabelAdaptiveSize:self.labelTime font:13];
        [self.butSmall addSubview:self.labelTime];

        if(ScreenWidth >=375){
            self.labelContent.frame = CGRectMake(15, 14, ScreenWidth-20-0.344*ScreenWidth,81);
            self.labelRemark.frame = CGRectMake(15, CGRectGetMaxY(self.labelContent.frame)+15, ScreenWidth-140,18);
            self.imageViewRight.frame = CGRectMake(CGRectGetMaxX(self.labelContent.frame), 13, 0.344*ScreenWidth,90);
            self.butSmall.frame = CGRectMake(10, self.imageViewRight.frame.size.height-24,self.imageViewRight.frame.size.width-20, 19);
            [self.butSmall.layer setCornerRadius:9.5];
            imageViewSanJiao.frame = CGRectMake(7,4,10, 10);
            self.labelTime.frame = CGRectMake(CGRectGetMaxX(imageViewSanJiao.frame)+2, 2, self.butSmall.frame.size.width-CGRectGetMaxX(imageViewSanJiao.frame)-4, 10);
        }else{
            self.labelContent.frame = CGRectMake(15, 16, ScreenWidth-20-0.344*ScreenWidth, 75);
            self.labelRemark.frame = CGRectMake(15, CGRectGetMaxY(self.labelContent.frame)+15, ScreenWidth-140, 14);
            self.imageViewRight.frame = CGRectMake(CGRectGetMaxX(self.labelContent.frame), 15, 0.344*ScreenWidth,80);
            self.butSmall.frame = CGRectMake(10, self.imageViewRight.frame.size.height-20,self.imageViewRight.frame.size.width-20, 15);
            [self.butSmall.layer setCornerRadius:7.5];
            imageViewSanJiao.frame = CGRectMake(7, 3,9, 9);
            self.labelTime.frame = CGRectMake(CGRectGetMaxX(imageViewSanJiao.frame)+2, 2, self.butSmall.frame.size.width-CGRectGetMaxX(imageViewSanJiao.frame)-4,9);
        }
    }
    return self;
}
-(void)setContentMg:(LSZSearchKeyContentMg *)contentMg
{
    self.labelContent.text = [NSString stringWithFormat:@"%@",contentMg.title];
    CGSize size = [self.labelContent sizeThatFits:CGSizeMake(self.labelContent.frame.size.width, 75)];
    self.labelContent.frame = CGRectMake(self.labelContent.frame.origin.x, self.labelContent.frame.origin.y, self.labelContent.frame.size.width,size.height);

    self.labelRemark.text = [NSString stringWithFormat:@"%@  浏览%@次",contentMg.source,contentMg.browseNum];
    NSString * number = [NSString stringWithFormat:@"%@次",contentMg.browseNum];
    [self.imageViewRight sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",contentMg.imageUrl]] placeholderImage:[UIImage imageNamed:@"placeholder"]];

    if(ScreenWidth >=375){
        self.labelRemark.frame = CGRectMake(15, 86, ScreenWidth-140,18);
        self.imageViewRight.frame = CGRectMake(CGRectGetMaxX(self.labelContent.frame), 13, 0.344*ScreenWidth, 90);
        CGFloat width =  [LSZSpecialPackaging   caculateWidthOfText:200 height:10 font:14 :number];

        self.butSmall.frame = CGRectMake((self.imageViewRight.frame.size.width-width)/2, self.imageViewRight.frame.size.height-24,width, 19);
    }else{
        self.labelRemark.frame = CGRectMake(15, 82, ScreenWidth-140, 14);
        self.imageViewRight.frame = CGRectMake(CGRectGetMaxX(self.labelContent.frame), 16, 0.344*ScreenWidth, 80);
        CGFloat width =  [LSZSpecialPackaging   caculateWidthOfText:200 height:9 font:12 :number];

        self.butSmall.frame = CGRectMake((self.imageViewRight.frame.size.width-width)/2, self.imageViewRight.frame.size.height-24,width, 15);
    }
    self.imageViewRight.contentMode = UIViewContentModeScaleAspectFill;
    self.imageViewRight.clipsToBounds = YES;//设置这个属性为YES就可以了，默认是NO;
}
@end
